package design_pattern.observer.demo01;

import lombok.Data;

/**
 * @version 1.0.0
 * Created by cyd on 2022-06-15 17:28:22
 * @ClassName : design_pattern.observer.demo01.ConcreteObserver
 * @Description : 具体观察者，实现抽象观察者的方法，同时使自生的状态和主题的状态相协调
 */
@Data
public class ConcreteObserver implements Observer {

    private String name;
    private String observerState;

    /**
     * 持有观察者的应用，即持有 特定主题的应用
     */
    private ConcreteSubject concreteSubject;

    public ConcreteObserver(String name, ConcreteSubject concreteSubject) {
        this.name = name;
        this.concreteSubject = concreteSubject;
    }

    @Override
    public void update() {
        observerState = concreteSubject.getSubjectState();
        System.out.println("观察者 " + name + " 的新状态是：" + observerState);
    }
}
